package cn.edu.lingnan.controller;


import cn.edu.lingnan.domain.Dto.FindStudentDto;
import cn.edu.lingnan.domain.Dto.UpdateStudentDto;
import cn.edu.lingnan.domain.Vo.StudentVo;
import cn.edu.lingnan.domain.pojo.PageBean;
import cn.edu.lingnan.domain.pojo.Student;
import cn.edu.lingnan.domain.pojo.academy;
import cn.edu.lingnan.service.StudentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
@Slf4j
public class StudentController {

    private final StudentService studentService;

    //查找学生信息
    @PostMapping("/findStudent")
    public Result<PageBean> findStudent(@RequestBody FindStudentDto findStudentDto) {
        log.info("findStudentDto={}", findStudentDto);
        PageBean pageResult=  studentService.list(findStudentDto);
        return  Result.success(pageResult);
    }

    //软删除学生信息
    @DeleteMapping("/deleteStudent")
    public Result deleteStudent( @RequestParam("userId") Integer userId) {
        log.info("deleteStudent={}", userId);
        Integer result = studentService.deleteStudent(userId);
        if (result == 0) {
            return Result.error("无法删除，该学生是项目负责人或成员");
        }
        return Result.success("删除成功");
    }

    //查询学院信息
    @GetMapping("/findAcademy")
    public Result<List<academy>> findAcademy() {
        log.info("findAcademy");
         List<academy> academy = studentService.findAcademy();
        return Result.success(academy);
    }
    //根据id查询学生信息
    @GetMapping("/findStudentById")
    public Result<StudentVo> findStudentById(@RequestParam("userId") Integer userId) {
        log.info("findStudentById={}", userId);
         StudentVo student = studentService.findStudentById(userId);
        return Result.success(student);
    }

    //修改学生信息
     @PostMapping("/updateStudent")
    public Result updateStudent(@RequestBody UpdateStudentDto updateStudentDto) {
        log.info("updateStudentDto={}", updateStudentDto);
        studentService.updateStudent(updateStudentDto);
        return Result.success("修改成功");

     }

    //查询老师信息
    @PostMapping("/findTeacher")
    public Result<PageBean> findTeacher(@RequestBody FindStudentDto findStudentDto) {
        log.info("findStudentDto={}", findStudentDto);
        PageBean pageResult=  studentService.listTeacher(findStudentDto);
        return  Result.success(pageResult);
    }

    //查找学生账号信息
    @PostMapping("/findStudentAccount")
    public Result<PageBean> findStudentAccount(@RequestBody FindStudentDto findStudentDto) {
        log.info("findStudentDto={}", findStudentDto);
        PageBean pageResult=  studentService.listAccount(findStudentDto);
        return  Result.success(pageResult);
    }

    //冻结或者解冻学生
    @PutMapping("/freezeOrUnfreeze")
    public Result freezeOrUnfreeze(@RequestParam("userId") Integer userId, @RequestParam("status") Integer status) {
        log.info("freezeOrUnfreeze={}", userId);
        studentService.freezeOrUnfreeze(userId, status);
        return Result.success("操作成功");
    }


}
